cmake_minimum_required(VERSION 3.0.0)
project(test1 VERSION 0.1.0)

include(CTest)
enable_testing()

add_compile_options(-std=c++17)

file(GLOB_RECURSE SRC_DIR_LIST ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*.c)	

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    file(GLOB_RECURSE LIB_DIR_LIST ${PROJECT_SOURCE_DIR}/lib/linux/*.so ${PROJECT_SOURCE_DIR}/lib/linux/*.a)
    set(LIBRARY_OUTPUT_PATH ../lib_creat/linux)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    file(GLOB_RECURSE LIB_DIR_LIST ${PROJECT_SOURCE_DIR}/lib/windows/*.dll ${PROJECT_SOURCE_DIR}/lib/windows/*.a)
    file(GLOB_RECURSE SHARE_LIB_DIR_LIST ${PROJECT_SOURCE_DIR}/lib/windows/*.dll)
    set(LIBRARY_OUTPUT_PATH ../lib_creat/windows)
ENDIF ()

include_directories(
    ${PROJECT_SOURCE_DIR}/include
)



add_library(base SHARED ${SRC_DIR_LIST})    #默认so会生成build目录
add_library(base_static STATIC ${SRC_DIR_LIST})
set_target_properties(base_static PROPERTIES OUTPUT_NAME "base")


IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    set(LIBRARYS  ${PROJECT_SOURCE_DIR}/lib_creat/linux/libbase.so)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    set(LIBRARYS  ${PROJECT_SOURCE_DIR}/lib_creat/windows/libbase.dll)
ENDIF ()

# link_libraries( 
#     ${LIBRARYS}
# )
add_executable(test1 
    ${PROJECT_SOURCE_DIR}/src/main.c
)
# 链接动态库到可执行文件
target_link_libraries(test1 PRIVATE base)

 # 把动态库添加到运行目录
 add_custom_command (TARGET test1 POST_BUILD
 COMMAND ${CMAKE_COMMAND} -E copy_if_different
 ${LIBRARYS} $<TARGET_FILE_DIR:test1>
 )

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)